class Solution {
public:
    vector<vector<int> > generate(int numRows) {
        // Start typing your C/C++ solution below
        // DO NOT write int main() function
        if (numRows < 1) {
            return vector<vector<int> >();
        }
        vector<int> old;
        vector<int> cur;
        vector<vector<int> > ans;

        cur.push_back(1);
        ans.push_back(cur);
        for (int i = 2; i <= numRows; ++i) {
            old = cur;
            vector<int>().swap(cur);
            for (int j = 0; j < i; ++j) {
                int t = 0;
                if (j - 1 >= 0) {
                    t += old[j - 1];
                }
                if (j < i - 1) {
                    t += old[j];
                }
                cur.push_back(t);
            }
            ans.push_back(cur);
        }
        return ans;
    }
};
